//
//  SwitchCell.m
//  QuXiang
//
//  Created by Duncan on 2020/6/30.
//  Copyright © 2020 NanHuaiZi. All rights reserved.
//

#import "SwitchCell.h"

@implementation SwitchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubviews:[NSArray arrayWithObjects:self.leftImageView, self.leftLabel, self.switchs, nil]];
        [self masonryLayout];
    }
    return self;
}

- (void)switchsClick {
    if (self.switchBlock) {
        self.switchBlock(self.switchs.isOn);
    }
}

// 直播管理
- (void)liveManaMasLayout {
    self.leftImageView.hidden = NO;
    self.leftLabel.textColor = [UIColor blackColor];
    [self.leftImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(16));
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(kFragmemtFloat(15));
    }];
    [self.leftLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftImageView.mas_right).offset(kFragmemtFloat(10));
        make.centerY.equalTo(self.contentView);
    }];
}

#pragma mark ------- Lazy Methods -------

- (void)masonryLayout {
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(15));
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(kFragmemtFloat(110));
    }];
    [self.switchs mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-kFragmemtFloat(15));
        make.centerY.equalTo(self.contentView);
    }];
}

- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc] init];
        _leftImageView.hidden = YES;
        _leftImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _leftImageView;
}

- (UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [UILabel initWithTextColor:k_Color_TipColor fontSize:15];
    }
    return _leftLabel;
}

- (UISwitch *)switchs {
    if (!_switchs) {
        _switchs = [[UISwitch alloc] init];
        _switchs.transform = CGAffineTransformMakeScale(0.7, 0.7);
        _switchs.backgroundColor = [UIColor whiteColor];
        _switchs.tintColor = k_Color_themeColor;
        _switchs.onTintColor = k_Color_themeColor;
        [_switchs addTarget:self action:@selector(switchsClick) forControlEvents:UIControlEventValueChanged];
    }
    return _switchs;
}

@end
